package main

import . "local/algorithm/util"

func binaryTreeRightSideView(root *TreeNode) []int {
	if root == nil {
		return []int{}
	}
	nq := []*TreeNode{root}
	size := 1
	ret := []int{}
	for len(nq) != 0 {
		node := nq[0]
		nq = nq[1:]
		size--
		if node.Left != nil {
			nq = append(nq, node.Left)
		}

		if node.Right != nil {
			nq = append(nq, node.Right)
		}

		if size == 0 {
			ret = append(ret, node.Val)
			size = len(nq)
		}
	}
	return ret
}
